package com.film.controller.movie;

import com.alibaba.fastjson.JSONObject;
import com.film.jwt.JwtUtil;
import com.film.service.impl.movie.GetMoviesByClassServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

//通过类别拉取电影
@RestController
public class GetMoviesByClassController {
    @Autowired
    private GetMoviesByClassServiceImpl getMoviesByClassService;

    @GetMapping("/movie/class/{className}/{token}")
    public JSONObject getMovies(@PathVariable String className, @PathVariable String token) throws SQLException {
        if (!JwtUtil.JwtVerify(token)) {
            JSONObject resp = new JSONObject();
            resp.put("error_message", "jwt验证错误");
            return resp;
        } else {
            return getMoviesByClassService.getMovies(className);
        }
    }
}
